﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FrameworkLib.Security
{
    /// <summary>
    /// Applied to controls as an indication that user must possess 
    /// rights to see/act on this control
    /// </summary>
    /// <example>
    /// In this example, you would add the following attribute to the text box corresponding to the salary data:
    ///
    /// [YourNamespace.Authorization("EditSalary", "ReadOnly", true)]
    /// private System.Windows.Forms.TextBox Salary;
    /// 
    /// the meaning is that if the currently logged in user doesn't have rights to "edit salary," 
    /// set the text box Salary's ReadOnly property to true.
    /// 
    /// Add this in a partial class of the designer of the form or control...
    /// </example>
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
    public class AuthorizationAttribute : System.Attribute
    {
        private string _operationName = null;
        private string _propertyName = null;
        private object _propertyValue = null;

        /// <summary>
        /// Constructor.  
        /// </summary>
        public AuthorizationAttribute(string operationName, string propertyName, object propertyValue)
        {
            _operationName = operationName;
            _propertyName = propertyName;
            _propertyValue = propertyValue;
        }

        /// <summary>
        /// OperationName must match action or task in AzMan.
        /// </summary>
        public string OperationName
        {
            get { return _operationName; }
        }

        /// <summary>
        /// Property name, which to invoke if logged in user doesn't 
        /// have rights to operation
        /// </summary>
        public string PropertyName
        {
            get { return _propertyName; }
        }

        /// <summary>
        /// Property value, which to set if logged in user doesn't 
        /// have rights to operation
        /// </summary>
        public object PropertyValue
        {
            get { return _propertyValue; }
        }
    }
}
